package com.bkgy.modularbx.coil_prod_stats.controller;

import com.bkgy.commom.model.QueryDTO;
import com.bkgy.modularbx.coil_prod_stats.dto.*;
import com.bkgy.modularbx.coil_prod_stats.service.TCoilProductionStatsService;
import com.bkgy.sys.common.entity.ResultData;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.media.Content;
import io.swagger.v3.oas.annotations.media.Schema;
import io.swagger.v3.oas.annotations.responses.ApiResponse;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import javax.validation.Valid;
import java.util.List;

/**
 * 钢种分卷统计控制器层
 *
 * @author dell
 * @date 2024-06-10
 */
@Tag(name = "钢种分卷统计管理", description = "钢种分卷统计接口")
@RestController
@RequestMapping("/coil_stats")
@Validated
public class TCoilProductionStatsController {

    @Resource
    private TCoilProductionStatsService coilProductionStatsService;

    @Operation(summary = "规格×钢种损失重量统计", description = "按照钢种和规格分组统计损失重量和损失比例")
    @ApiResponse(content = @Content(mediaType = "application/json",
            schema = @Schema(implementation = CoilStatsResultDTO.class)))
    @PostMapping("/steel_grade_by_spec")
    public ResultData<List<CoilStatsResultDTO>> statsSteelGradeBySpec(
            @Parameter(description = "查询条件")
            @RequestBody @Valid CoilStatsQueryDTO queryDTO) {
        return coilProductionStatsService.statsSteelGradeBySpec(queryDTO);
    }
    
    @Operation(summary = "缺陷原因损失重量统计", description = "按照缺陷原因分组统计损失重量和损失比例")
    @ApiResponse(content = @Content(mediaType = "application/json",
            schema = @Schema(implementation = DefectReasonResultDTO.DefectReasonResponse.class)))
    @PostMapping("/defect_reason_loss")
    public ResultData<DefectReasonResultDTO.DefectReasonResponse> statsDefectReasonLoss(
            @Parameter(description = "查询条件")
            @RequestBody @Valid DefectReasonQueryDTO queryDTO) {
        return coilProductionStatsService.statsDefectReasonLoss(queryDTO);
    }
    
    @Operation(summary = "来料卷重范围统计", description = "按照钢种、规格宽度、规格厚度、订单重量范围分组统计平均成材率")
    @ApiResponse(content = @Content(mediaType = "application/json",
            schema = @Schema(implementation = MaterialWeightRangeResultDTO.class)))
    @PostMapping("/material_weight_range")
    public ResultData<List<MaterialWeightRangeResultDTO>> statsMaterialWeightRange(
            @Parameter(description = "查询条件")
            @RequestBody @Valid QueryDTO<MaterialWeightRangeQueryDTO> queryDTO) {
        return coilProductionStatsService.statsMaterialWeightRange(queryDTO);
    }
} 
